﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.Practices.Unity;
using ePlanet.ArchiveMange.Services;
using ePlanet.ArchiveMange.Enum;

namespace Web.Views.ArchiveView
{
    /// <summary>
    /// 档案预览分发类
    /// </summary>
    public partial class ArchivePreview : PageBase
    {
        #region 属性
        /// <summary>
        /// 文档类型ID
        /// </summary>
        public int ArchiveTypeID
        {
            get
            {
                int o_int = 0;
                if (Request.QueryString["archivetype"] != null)
                {
                    if (int.TryParse(Request.QueryString["archivetype"], out o_int))
                    {
                        return o_int;
                    }
                    else
                    {
                        throw new Exception("档案类型错误");
                    }
                }
                else
                {
                    throw new Exception("档案类型不能为空");
                }
            }
        }

        [Dependency]
        public IArchiveMenuService ArchiveMenuService
        {
            get;
            set;
        }
        #endregion

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string urlFormat = "../ArchiveView/{0}?{1}";
                string param = string.Empty;
                foreach (string key in Request.QueryString.AllKeys)
                {
                    param += key + "=" + Request.QueryString[key] + "&";
                }
                param = param.Remove(param.Length - 1, 1);
                int baseTypeId = ArchiveMenuService.GetArchiveBaseIDById(ArchiveTypeID);
                switch (baseTypeId)
                {
                    //文书类
                    case ((int)ArchiveBaseType.Document):
                        this.Response.Redirect(string.Format(urlFormat, "DocumentView.aspx", param));
                        break;
                    //会计类
                    case ((int)ArchiveBaseType.Account):
                        this.Response.Redirect(string.Format(urlFormat, "AccountView.aspx", param));
                        break;
                    //基建类 
                    case ((int)ArchiveBaseType.BulidProject):
                        this.Response.Redirect(string.Format(urlFormat, "BuildProjectView.aspx", param));
                        break;
                    //设备类
                    case ((int)ArchiveBaseType.Equipment):
                        this.Response.Redirect(string.Format(urlFormat, "EquipmentView.aspx", param));
                        break;
                    //油气勘探类
                    case ((int)ArchiveBaseType.OliSearch):
                        this.Response.Redirect(string.Format(urlFormat, "OliSearchView.aspx", param));
                        break;
                    //音像类
                    case ((int)ArchiveBaseType.AudioVedio):
                        this.Response.Redirect(string.Format(urlFormat, "AudioView.aspx", param));
                        break;
                    //实物类
                    case ((int)ArchiveBaseType.RealKind):
                        this.Response.Redirect(string.Format(urlFormat, "RealKindView.aspx", param));
                        break;
                    //科研类
                    case ((int)ArchiveBaseType.Technology):
                        this.Response.Redirect(string.Format(urlFormat, "TechView.aspx", param));
                        break;
                    //光盘类
                    case ((int)ArchiveBaseType.CDKind):
                        this.Response.Redirect(string.Format(urlFormat, "CDView.aspx", param));
                        break;
                }
            }
        }
    }
}